/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.mb;

import br.siagefi.model.FornecedorPF;
import br.siagefi.service.FornecedorPFService;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Paulo Lavarini
 */
@SessionScoped
@ManagedBean
public class FornecedorPFBean implements Serializable{
    
    private FornecedorPF fornecedorPF;
    private final FornecedorPFService service;
    private List<FornecedorPF> fornecedoresPF;

    public FornecedorPFBean() {
        this.fornecedorPF = new FornecedorPF();
        this.service = new FornecedorPFService();
        this.carregarLista();
    }
    
     public final void carregarLista(){
         this.fornecedoresPF = service.listar();
    }
    
    public String gravar(){
        service.inserir(this.getFornecedorPF());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "fornecedorPF?faces-redirect=true";
    }
    
    public String alterar(FornecedorPF fornecedorPF){
        this.setFornecedorPF(fornecedorPF);
        return "incluirFornecedorPF";
    }
    
     public String remover(){
        service.remover(this.getFornecedorPF());
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "fornecedorPF";
    }
     
    public String remover(FornecedorPF fornecedorPF){
        service.remover(fornecedorPF);
        this.limparFormularioDoJsf();
        this.carregarLista();
        return "fornecedorPF";
    }
  
    public void limparFormularioDoJsf(){
        this.fornecedorPF = new FornecedorPF();
    }

    public FornecedorPF getFornecedorPF() {
        return fornecedorPF;
    }

    public void setFornecedorPF(FornecedorPF fornecedorPF) {
        this.fornecedorPF = fornecedorPF;
    }

    public List<FornecedorPF> getFornecedoresPF() {
        return fornecedoresPF;
    }

    public void setFornecedorPFs(List<FornecedorPF> fornecedoresPF) {
        this.fornecedoresPF = fornecedoresPF;
    }
}
